package com.neusoft.neuiotms.dcom.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.bean.TreeBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.KnowledgeTypeDTO;
import com.neusoft.neuiotms.dcom.service.KnowledgeTypeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
 * 
 * @author Liukq
 *
 */
@Api(tags = "知识库配置")
@RestController
@RequestMapping(value="/api/w/knowledgeType")
public class KnowlegeTypeController {
    
    @Autowired
    private KnowledgeTypeService knowledgeTypeService;
    
    @ApiOperation("查询所有知识配置类型")
    @GetMapping
    public ResultListDTO<KnowledgeTypeDTO> index(){
        final List<KnowledgeTypeDTO>  knowledgeTypeDTOs =  this.knowledgeTypeService.findAll();
        return ResultListDTO.success(knowledgeTypeDTOs);       
    }
    
    @ApiOperation("分页查询所有知识配置类型")
    @GetMapping("/p")
    public PageResultDTO<KnowledgeTypeDTO> search(final Pageable pageable,final Searchable searchable){
        return PageResultDTO.success(this.knowledgeTypeService.search(pageable,searchable));
    }
    
    @ApiOperation("创建知识配置类型")
    @PostMapping("")
    public ResultDTO<KnowledgeTypeDTO> create(@RequestBody final KnowledgeTypeDTO dto){
        final KnowledgeTypeDTO result = this.knowledgeTypeService.create(dto);
        return ResultDTO.success(result);
    }
    
    @ApiOperation("修改知识配置类型")
    @PutMapping("/{id}")
    public ResultDTO<KnowledgeTypeDTO> update(@PathVariable final Long id,
            @RequestBody final KnowledgeTypeDTO dto){
        final KnowledgeTypeDTO result = this.knowledgeTypeService.update(id,dto);
        return ResultDTO.success(result);
    }
    
    @ApiOperation("知识配置类型详情")
    @GetMapping("/{id}")
    public ResultDTO<KnowledgeTypeDTO> details(@PathVariable final Long id){
        final KnowledgeTypeDTO dto = this.knowledgeTypeService.details(id);
        return ResultDTO.success(dto);
    }
    
    @ApiOperation("删除知识配置类型")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id){
        this.knowledgeTypeService.delete(id);
        return ResultDTO.success();
    }
    
    @ApiOperation("知识类型树")
    @GetMapping("/tree")
    public ResultListDTO<TreeBean> tree(){
        return ResultListDTO.success(this.knowledgeTypeService.tree());
    }
}
